package servlet;

import dao.BaseDao;
import pojo.Anime;
import service.UserService;
import service.implement.UserServiceImplement;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.List;

public class AnimeServlet extends BaseServlet{

    private UserService userService=new UserServiceImplement();

    //处理searchbutton的Name搜索逻辑

    protected void nameSearch(HttpServletRequest request, HttpServletResponse response)
    {

        String animeName=request.getParameter("animeName");

        List<Anime> animeList=userService.searchAnimeList(animeName,"name");

        request.setAttribute("animeList",animeList);
        try {
            request.getRequestDispatcher("/pages/category.jsp").forward(request,response);
        } catch (ServletException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    //处理searchbutton的genre搜索逻辑

    protected void genreSearch(HttpServletRequest request,HttpServletResponse response){
        String animeGenre=request.getParameter("genreType");
        List<Anime> animeList=userService.searchAnimeList(animeGenre,"genre");

        request.setAttribute("animeList",animeList);
        try {
            request.getRequestDispatcher("/pages/category.jsp").forward(request,response);
        } catch (ServletException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    // 处理searchbutton的Type搜索逻辑

    protected void typeSearch(HttpServletRequest request,HttpServletResponse response){


        String animeType=request.getParameter("typeType");
        List<Anime> animeList=userService.searchAnimeList(animeType,"type");

        request.setAttribute("animeList",animeList);
        try {
            request.getRequestDispatcher("/pages/category.jsp").forward(request,response);
        } catch (ServletException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

}
